/* Sokoban
 * HIT3243
 * Authors: Mike Blackney, Ben Ingarfield, Kurniawan
 */

#include "pawnlist.h"
#include "registrar.h"

#define X_COLLIDE_THRESHOLD 0.25f
#define Y_COLLIDE_THRESHOLD 0.25f
#define Z_COLLIDE_THRESHOLD 0.5f

// [[ struct AutoPawn ]]

AutoPawn::AutoPawn( ) {}
	
AutoPawn::AutoPawn( Pawn &rPawn )
:	pawn(&rPawn) {
}

AutoPawn::AutoPawn( const AutoPawn &other )
:	pawn(NULL) {
	pawn = other.pawn;
}

bool AutoPawn::operator <( const AutoPawn &other ) const {
	return *pawn.get( ) < *other.pawn.get( );
}

bool AutoPawn::operator ==( const AutoPawn &other ) const {
	return pawn.get( ) == other.pawn.get( );
}

Pawn* AutoPawn::operator ->( ) const {
	return &*pawn;
}


// [[ class PawnList ]]
void PawnList::Add( Pawn &pawn ) {
	pawns.push_back( pawn );
}

void PawnList::Clear( ) {
	pawns.clear( );
}

void PawnList::Update( double fTime, float fElapsedTime ) {

	// Call the AI functions of all the pawns:
	std::list<AutoPawn>::iterator i;
	for ( i = pawns.begin( ); i != pawns.end( ); ++i) 
		(*i)->Update( fTime, fElapsedTime );
	
}

void PawnList::Render3D( IDirect3DDevice9 *pd3dDevice, double fTime, float fElapsedTime ) {
	// Best thing about 3d is that we don't need to sort the
	// list before we render!  Woot, etc.

	// Render the list:
	std::list<AutoPawn>::iterator i;

	for ( i = pawns.begin( ); i != pawns.end( ); ++i ) 
		(*i)->Render3D( pd3dDevice, fTime, fElapsedTime );
}